package com.umeng.analytics;

import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.text.TextUtils;

import com.umeng.analytics.MobclickAgent.EScenarioType;
import com.umeng.analytics.pro.ap;
import com.umeng.analytics.pro.ar;
import com.umeng.analytics.pro.as;
import com.umeng.analytics.pro.at;
import com.umeng.analytics.pro.ay;
import com.umeng.analytics.pro.ba;
import com.umeng.analytics.pro.bd;
import com.umeng.analytics.pro.bf;
import com.umeng.analytics.pro.bt;
import com.umeng.analytics.pro.bv;
import com.umeng.analytics.pro.bx;
import com.umeng.analytics.pro.by;
import com.umeng.analytics.pro.bz;
import com.umeng.analytics.pro.cb;
import com.umeng.analytics.pro.f;
import com.umeng.analytics.pro.m;
import com.umeng.analytics.pro.w;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.microedition.khronos.opengles.GL10;

public class b implements ay {
    private Context a;
    private bx b;
    private as c;
    private bf d;
    private bd e;
    private at f;
    private ar g;
    private ap h;
    private m i;
    private static final String j = "sp";
    private boolean k;
    private boolean l;
    private JSONObject m;
    private boolean n;

    b() {

        this.a = null;
        this.c = new as();
        this.d = new bf();
        this.e = new bd();
        this.f = null;
        this.g = null;
        this.h = null;
        this.i = null;
        this.k = false;
        this.l = false;
        this.m = null;
        this.n = false;
        this.c.a(((ay) this));
    }

    public void a(Context arg9, String arg10, String arg11, long arg12, int arg14) {
        try {
            if (!this.k || !this.n) {
                this.g(arg9);
            }

            this.f.a(arg10, arg11, arg12, arg14);
        } catch (Exception v0) {
            if (!by.a) {
                return;
            }

            by.e(((Throwable) v0));
        }
    }

    void a(Context arg3, String arg4, Map arg5, long arg6) {
        try {
            if (!this.k || !this.n) {
                this.g(arg3);
            }

            this.f.a(arg4, arg5, arg6);
        } catch (Exception v0) {
            if (!by.a) {
                return;
            }

            by.e(((Throwable) v0));
        }
    }

    public void a(Context arg3, List arg4, int arg5, String arg6) {
        try {
            if (!this.k || !this.n) {
                this.g(arg3);
            }

            this.f.a(arg4, arg5, arg6);
        } catch (Exception v0) {
            if (!by.a) {
                return;
            }

            by.e(((Throwable) v0));
        }
    }

    void a(String arg2) {
        if (!AnalyticsConfig.ACTIVITY_DURATION_OPEN) {
            try {
                this.d.a(arg2);
            } catch (Exception v0) {
            }
        }
    }

    void a(final String arg3, final String arg4) {
        try {
            bz.a(new cb() {
                @Override
                public void a() {
                    String[] v0 = com.umeng.analytics.c.a(com.umeng.analytics.b.b(b.this));
                    if (v0 == null || !arg3.equals(v0[0]) || !arg4.equals(v0[1])) {
                        com.umeng.analytics.b.c(b.this).a(com.umeng.analytics.b.b(b.this)).a(com.umeng.analytics.b.b(b.this));
                        boolean v0_1 = b.this.a().e(com.umeng.analytics.b.b(b.this));
                        ar.b(com.umeng.analytics.b.b(b.this)).b();
                        if (v0_1) {
                            b.this.a().f(com.umeng.analytics.b.b(b.this));
                        }
                        com.umeng.analytics.c.a(com.umeng.analytics.b.b(b.this), arg3, arg4);
                    }
                }
            });
        } catch (Exception v0) {
            if (!by.a) {
                return;
            }

            by.e(" Excepthon  in  onProfileSignIn", ((Throwable) v0));
        }
    }

    void a(final Context arg3) {
        if (arg3 == null) {
            by.e("unexpected null context in onResume");
            return;
        }

        if (AnalyticsConfig.ACTIVITY_DURATION_OPEN) {
            this.d.a(arg3.getClass().getName());
        }

        try {
            if (!this.k || !this.n) {
                this.g(arg3);
            }

            bz.a(new cb() {
                @Override
                public void a() {
                    com.umeng.analytics.b.a(b.this, arg3.getApplicationContext());
                }
            });
        } catch (Exception v0) {
            by.e("Exception occurred in Mobclick.onResume(). ", ((Throwable) v0));
        }
    }

    void a(Context arg5, String arg6) {
        if (!TextUtils.isEmpty(((CharSequence) arg6))) {
            if (arg5 == null) {
                by.e("unexpected null context in reportError");
                return;
            }

            try {
                if (!this.k || !this.n) {
                    this.g(arg5);
                }

                JSONObject v0_1 = new JSONObject();
                v0_1.put("ts", System.currentTimeMillis());
                v0_1.put("error_source", 2);
                v0_1.put("context", arg6);
                w.a(this.a).a(bd.a(), v0_1.toString(), 2);
            } catch (Exception v0) {
                if (!by.a) {
                    return;
                }

                by.e(((Throwable) v0));
            }
        }
    }

    void a(Context arg3, Throwable arg4) {
        if (arg3 != null && arg4 != null) {
            try {
                this.a(arg3, bt.a(arg4));
            } catch (Exception v0) {
                if (!by.a) {
                    return;
                }

                by.e(((Throwable) v0));
            }
        }
    }

    void a(boolean arg1) {
        AnalyticsConfig.CATCH_EXCEPTION = arg1;
    }

    void a(long arg2) {
        AnalyticsConfig.sLatentWindow = (((int) arg2)) * 1000;
    }

    void a(double arg4, double arg6) {
        if (AnalyticsConfig.a == null) {
            AnalyticsConfig.a = new double[2];
        }

        AnalyticsConfig.a[0] = arg4;
        AnalyticsConfig.a[1] = arg6;
    }

    void a(GL10 arg4) {
        String[] v0 = bv.a(arg4);
        if (v0.length == 2) {
            AnalyticsConfig.GPU_VENDER = v0[0];
            AnalyticsConfig.GPU_RENDERER = v0[1];
        }
    }

    void a(Context arg2, EScenarioType arg3) {
        if (arg2 != null) {
            this.a = arg2.getApplicationContext();
        }

        if (arg3 != null) {
            this.a(arg2, arg3.toValue());
        }
    }

    void a(MobclickAgent.UMAnalyticsConfig arg3) {
        if (arg3.mContext != null) {
            this.a = arg3.mContext.getApplicationContext();
        }

        if (!TextUtils.isEmpty(arg3.mAppkey)) {
            AnalyticsConfig.a(arg3.mContext, arg3.mAppkey);
            if (!TextUtils.isEmpty(arg3.mChannelId)) {
                AnalyticsConfig.a(arg3.mChannelId);
            }

            AnalyticsConfig.CATCH_EXCEPTION = arg3.mIsCrashEnable;
            this.a(this.a, arg3.mType);
        } else {
            by.e("the appkey is null!");
        }
    }

    static boolean a(b arg0, boolean arg1) {
        arg0.l = arg1;
        return arg1;
    }

    static m a(b arg1) {
        return arg1.i;
    }

    static void a(b arg0, Context arg1) {
        arg0.h(arg1);
    }

    public bd a() {
        return this.e;
    }

    public void a(Context arg1, int arg2) {
        AnalyticsConfig.a(arg1, arg2);
    }

    public void a(Context arg1, String arg2, Object arg3) {
    }

    public void a(Context arg3, String arg4, HashMap arg5) {
        try {
            if (!this.k || !this.n) {
                this.g(arg3);
            }

            this.f.b(arg4, ((Map) arg5));
        } catch (Exception v0) {
            if (!by.a) {
                return;
            }

            by.e(((Throwable) v0));
        }
    }

    public void a(Context arg1, String arg2, Map arg3) {
    }

    public void a(Context arg2, List arg3) {
        try {
            if (!this.k || !this.n) {
                this.g(arg2);
            }

            this.f.a(arg2, arg3);
        } catch (Exception v0) {
            by.e(((Throwable) v0));
        }
    }

    public void a(bx arg1) {
        this.b = arg1;
    }

    public void a(Throwable arg5) {
        try {
            this.d.a();
            if (this.a != null) {
                if (arg5 != null && this.g != null) {
                    JSONObject v0_1 = new JSONObject();
                    v0_1.put("ts", System.currentTimeMillis());
                    v0_1.put("error_source", 1);
                    v0_1.put("context", bt.a(arg5));
                    w.a(this.a).a(bd.a(), v0_1.toString(), 1);
                }

                this.i.e();
                this.h.a(this.a);
                this.i(this.a);
                ba.a(this.a).edit().commit();
            }

            bz.a();
        } catch (Exception v0) {
            if (!by.a) {
                return;
            }

            by.e("Exception in onAppCrash", ((Throwable) v0));
        }
    }

    void b(String arg2) {
        if (!AnalyticsConfig.ACTIVITY_DURATION_OPEN) {
            try {
                this.d.b(arg2);
            } catch (Exception v0) {
            }
        }
    }

    void b(final Context arg3) {
        if (arg3 == null) {
            by.e("unexpected null context in onPause");
            return;
        }

        if (AnalyticsConfig.ACTIVITY_DURATION_OPEN) {
            this.d.b(arg3.getClass().getName());
        }

        try {
            if (!this.k || !this.n) {
                this.g(arg3);
            }

            bz.a(new cb() {
                @Override
                public void a() {
                    com.umeng.analytics.b.b(b.this, arg3.getApplicationContext());
                    com.umeng.analytics.b.a(b.this).f();
                }
            });
        } catch (Exception v0) {
            if (!by.a) {
                return;
            }

            by.e("Exception occurred in Mobclick.onRause(). ", ((Throwable) v0));
        }
    }

    void b() {
        try {
            bz.a(new cb() {
                @Override
                public void a() {
                    String[] v0 = com.umeng.analytics.c.a(com.umeng.analytics.b.b(b.this));
                    if (v0 != null && !TextUtils.isEmpty(v0[0]) && !TextUtils.isEmpty(v0[1])) {
                        com.umeng.analytics.b.c(b.this).a(com.umeng.analytics.b.b(b.this)).a(com.umeng.analytics.b.b(b.this));
                        boolean v0_1 = b.this.a().e(com.umeng.analytics.b.b(b.this));
                        ar.b(com.umeng.analytics.b.b(b.this)).b();
                        if (v0_1) {
                            b.this.a().f(com.umeng.analytics.b.b(b.this));
                        }

                        com.umeng.analytics.c.b(com.umeng.analytics.b.b(b.this));
                    }
                }
            });
        } catch (Exception v0) {
            if (!by.a) {
                return;
            }

            by.e(" Excepthon  in  onProfileSignOff", ((Throwable) v0));
        }
    }

    void b(boolean arg1) {
        AnalyticsConfig.ACTIVITY_DURATION_OPEN = arg1;
    }

    void b(Context arg2, String arg3) {
        if (arg2 != null) {
            this.a = arg2.getApplicationContext();
        }

        AnalyticsConfig.b(arg2, arg3);
    }

    void b(long arg2) {
        AnalyticsConfig.kContinueSessionMillis = arg2;
    }

    static void b(b arg0, Context arg1) {
        arg0.i(arg1);
    }

    static Context b(b arg1) {
        return arg1.a;
    }

    void c(boolean arg1) {
        com.umeng.analytics.a.d = arg1;
    }

    static ar c(b arg1) {
        return arg1.g;
    }

    void c(Context arg2) {
        try {
            if (!this.k || !this.n) {
                this.g(arg2);
            }

            this.g.a();
        } catch (Throwable v0) {
        }
    }

    public void c(Context arg1, String arg2) {
    }

    void d(Context arg3) {
        try {
            this.h.a(arg3);
            this.d.a();
            this.i(arg3);
            ba.a(arg3).edit().commit();
            this.i.d();
            bz.a();
        } catch (Exception v0) {
            if (!by.a) {
                return;
            }

            v0.printStackTrace();
        }
    }

    void d(boolean arg1) {
        by.a = arg1;
    }

    public Object d(Context arg2, String arg3) {
        return null;
    }

    void e(boolean arg1) {
        AnalyticsConfig.a(arg1);
    }

    public String e(Context arg2) {
        return null;
    }

    public void f(Context arg1) {
    }

    private void g(Context arg4) {
        if (arg4 != null) {
            try {
                if (Build.VERSION.SDK_INT > 13 && !this.n && ((arg4 instanceof Activity))) {
                    this.h = new ap((Activity) arg4);
                    this.n = true;
                }

                if (this.k) {
                    return;
                }

                this.a = arg4.getApplicationContext();
                this.f = new at(this.a);
                this.g = ar.b(this.a);
                this.k = true;
                if (this.i == null) {
                    this.i = com.umeng.analytics.pro.m.a(this.a);
                }

                if (this.l) {
                    return;
                }

                bz.b(new cb() {
                    @Override
                    public void a() {
                        com.umeng.analytics.b.a(b.this).a(new f() {
                            public void a(Object arg3, boolean arg4) {
                                com.umeng.analytics.b.a(com.umeng.analytics.b.this, true);
                            }
                        });
                    }
                });
            } catch (Throwable v1) {
            }
        }
    }

    private void h(Context arg2) {
        this.e.c(arg2);
        if (this.b != null) {
            this.b.a();
        }
    }

    private void i(Context arg3) {
        this.e.d(arg3);
        bf.a(arg3);
        ap.b(arg3);
        this.g.a(this.a).a(arg3);
        if (this.b != null) {
            this.b.b();
        }
    }

    private JSONObject j(Context arg5) {
        JSONObject v1 = null;
        try {
            String v2 = ba.a(arg5).getString("sp", null);
            if (TextUtils.isEmpty(((CharSequence) v2))) {
                return v1;
            }

            JSONObject v0_1 = new JSONObject(v2);
            return v0_1;
        } catch (Exception v0) {
            v0.printStackTrace();
        }

        return v1;
    }
}

